// 计算年龄
function calculateAge(birthDate) {
    let dateOfBirth = new Date(birthDate)  // 获取当前时间的 Date 对象  
    let currentDate = new Date()  // 计算年龄，单位是毫秒，需要将毫秒转换为年  
    let age = (currentDate - dateOfBirth) / (365 * 24 * 60 * 60 * 1000)  // 取整数部分，表示整岁数  
    return Math.floor(age)
}

// 计算星座
function getStart(date) {
    let dateArr = date.split('-')
    let month = dateArr[1]
    let day = dateArr[2]
    let startType = null
    switch (month) {
        case "01":
            if (day > 19) { startType = ("水瓶座") }
            else startType = ("摩羯座")
            break
        case "02":
            if (day > 18) { startType = ("双鱼座") }
            else startType = ("水瓶座")
            break
        case "03":
            if (day > 20) { startType = ("白羊座") }
            else startType = ("双鱼座")
            break
        case "04":
            if (day > 19) { startType = ("金牛座") }
            else startType = ("白羊座")
            break
        case "05":
            if (day > 20) { startType = ("双子座") }
            else startType = ("金牛座")
            break
        case "06":
            if (day > 21) { startType = ("巨蟹座") }
            else startType = ("双子座")
            break
        case "07":
            if (day > 22) { startType = ("狮子座") }
            else startType = ("巨蟹座")
            break
        case "08":
            if (day > 22) { startType = ("处女座") }
            else startType = ("狮子座")
            break
        case "09":
            if (day > 22) { startType = ("天秤座") }
            else startType = ("处女座")
            break
        case "10":
            if (day > 23) { startType = ("天蝎座") }
            else startType = ("天秤座")
            break
        case "11":
            if (day > 20) { startType = ("射手座") }
            else startType = ("天蝎座")
            break
        case "12":
            if (day > 21) { startType = ("摩羯座") }
            else startType = ("射手座")
            break
    }
    return startType
}

// 获取当前时间
function getNowTime() {
    const date = new Date()
    const year = date.getFullYear()
    const month = date.getMonth() + 1
    const day = date.getDate()
    return `${year}年${month}月${day}日`
}

// 获取当前具体时间
function getNowSpecTime() {
    const date = new Date()
    const year = date.getFullYear()
    const month = date.getMonth() + 1
    const day = date.getDate()
    const hour = date.getHours()
    const min = date.getMinutes()
    return `${year}-${month}-${day} ${hour}:${min}`
}

// 生成随机数
function getRandom(min, max) {
    return Math.floor(Math.random() * (max + 1 - min) + min)
}

// 群主页用来判断是否是00后
function is00sBorn(birthDate) {
    var birthYear = parseInt(birthDate.substr(0, 4))
    return birthYear >= 2000
}

// 提取文件后缀名
const extractExt = fileName => {
    return fileName.slice(fileName.lastIndexOf('.'), fileName.length)
}

// 深拷贝
function deepClone(data) {
    let cloneobj = Object.assign({}, data)
    for (let key in data) {
        if (typeof cloneobj[key] === 'object') {
            cloneobj[key] = deepClone(cloneobj[key])
        }
    }
    return cloneobj
}

module.exports = {
    calculateAge,
    getStart,
    getNowTime,
    getNowSpecTime,
    getRandom,
    is00sBorn,
    extractExt,
    deepClone
}